package com.immo.libcommon.utils;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;

/**
 * @author Administrator
 * @content 复制到剪贴板
 * @date 2018/7/30
 */
public class CopyUtil {
    public static void copyContent(Context context, String content) {
        // 得到剪贴板管理器
        ClipboardManager clipboardManager =
                (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        assert clipboardManager != null;
        clipboardManager.setPrimaryClip(ClipData.newPlainText(null, content));
        if (clipboardManager.hasPrimaryClip()) {
            clipboardManager.getPrimaryClip().getItemAt(0).getText();
        }
        ToastUtils.showToast(context, "已复制到粘贴板");
    }

}
